package com.xiaozou.domain;


import lombok.Getter;

import java.io.Serializable;


@Getter
public class BaseResult<T> implements Serializable {

    public static final int FAILED = 0;
    public static final int SUCCESS = 1;
    public static final String SUCCESS_MSG = "操作成功!";
    public static final String FAILED_MSG = "操作失败!";

    private int code;
    private String msg;
    private T data;

    public BaseResult() {

    }
    public BaseResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> BaseResult<T> success(T data) {
        return new BaseResult(SUCCESS, SUCCESS_MSG, data);
    }

    public static <T> BaseResult<T> fail(String msg) {
        return new BaseResult(FAILED, msg, null);
    }

    public boolean isSuccess() {
        return this.getCode() == SUCCESS;
    }

}
